import Questions.TestQuestion;
import org.junit.Before;
import org.junit.Test;

import java.io.ByteArrayOutputStream;
import java.io.PrintStream;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
/**
 * Created by:
 * User: Igor Martynovich and Guzenko Igor
 * Date: 20.11.13
 */
public class TestTestQuestion {
    TestQuestion testQuestion;
    String[] variants;
    private final ByteArrayOutputStream outContent = new ByteArrayOutputStream();
    @Before
    public void initTestQuestion(){
        variants = new String[]{"badAnswer1", "rightAnswer", "badAnswer2"};
        testQuestion = new TestQuestion("question","rightAnswer",variants);
    }

    @Test
    public void testAskQuestion(){
        System.setOut(new PrintStream(outContent));
        String expectedOut ="\nquestion\n1 badAnswer1\n2 rightAnswer\n3 badAnswer2";
        testQuestion.askQuestion();
        assertEquals(expectedOut, outContent.toString());
    }

    @Test
    public void testSerialize(){
        String expectedResult ="question\nrightAnswer\nbadAnswer1\nrightAnswer\nbadAnswer2";
        String actualResult = testQuestion.serialize("\n");
        assertTrue(expectedResult.equals(actualResult));
    }
}
